window.onload=function(){
    // localStorage.removeItem('userInfo')
 var zhuces
    document.getElementsByClassName('denglu1')[0].onclick=function(){
         var istrue0=false
  var istrue1=false
  var istrue2=false
  var istrue3=false

       var num = document.getElementById('tele').value
       var  pwd   = document.getElementById('pwd').value
        var name   =document.getElementById('name').value
        var newpwd= document.getElementById('newpwd').value
        var zhuce=[{"num":num,"pwd":pwd,"name":name}]

      


        if(document.querySelector('[type="checkbox"]').checked !=true){
            alert("请勾选")
            return
        }
       var reg=/^1[3456789]\d{9}$/
       var reg1=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/
       if(num==''){
        document.getElementsByClassName('zhanghao')[0].nextElementSibling.innerHTML="输入手机号"
        document.getElementsByClassName('zhanghao')[0].nextElementSibling.style.visibility='visible' 
        istrue0=false
       
       }
     else if( !reg.test(num)){
        document.getElementsByClassName('zhanghao')[0].nextElementSibling.innerHTML="手机号不正确"
        document.getElementsByClassName('zhanghao')[0].nextElementSibling.style.visibility='visible' 
        istrue0=false
       }
        else{
            document.getElementsByClassName('zhanghao')[0].nextElementSibling.style.visibility='hidden' 
            istrue0=true 
        }      
       if(name==''){
        document.getElementsByClassName('mima')[0].nextElementSibling.innerHTML="输入姓名"
        document.getElementsByClassName('mima')[0].nextElementSibling.style.visibility='visible' 
        istrue1=false       
               
            }
        else{
            document.getElementsByClassName('mima')[0].nextElementSibling.style.visibility='hidden'  
            istrue1=true
        }
       if(pwd==''){
        document.getElementsByClassName('mima')[1].nextElementSibling.innerHTML="输入密码"
        document.getElementsByClassName('mima')[1].nextElementSibling.style.visibility='visible'   
        istrue2=false
           
       }
       else if(!reg1.test(pwd)){
        document.getElementsByClassName('mima')[1].nextElementSibling.innerHTML="密码至少八位且字母数字混合"
        document.getElementsByClassName('mima')[1].nextElementSibling.style.visibility='visible'
        istrue2=false   
        
       }
       else{
        document.getElementsByClassName('mima')[1].nextElementSibling.style.visibility='hidden' 
        istrue2=true
       }
       if(newpwd==''){
        document.getElementsByClassName('mima')[2].nextElementSibling.innerHTML="输入确认密码"
        document.getElementsByClassName('mima')[2].nextElementSibling.style.visibility='visible' 
        istrue3=false
       }
       else if(newpwd!=pwd){
        document.getElementsByClassName('mima')[2].nextElementSibling.innerHTML="密码不一致"
        document.getElementsByClassName('mima')[2].nextElementSibling.style.visibility='visible'  
        istrue3=false 
         
       }
       else{
        document.getElementsByClassName('mima')[2].nextElementSibling.style.visibility='hidden' 
        istrue3=true
       }
      
      if(istrue0&&istrue2&&istrue1&&istrue3){

if( localStorage['userInfo']){
    zhuces=JSON.parse(localStorage['userInfo']) 
    
}
else{
    zhuces=[]
}
var zhuce=[{"num":num,"pwd":pwd,"name":name}]

for( var i=0;i<zhuces.length;i++){
    //console.log(zhuces[i][0].num)
    if( zhuce[0].num == zhuces[i][0].num){
        // document.getElementsByClassName('mima')[1].nextElementSibling.innerHTML="手机号码已注册，请登录"
        // document.getElementsByClassName('mima')[1].nextElementSibling.style.visibility='visible'
        alert('"手机号码已注册，请登录"')
        location.href="login.html"
        num=''
        name=''
       return

      
}
  
}
zhuces.push([{"num":num,"pwd":pwd,"name":name}])
   localStorage['userInfo']=JSON.stringify(zhuces) 
           location.href="login.html"
           
     }
 
}
}